
import Toast from '@vant/weapp/toast/toast';
const app = getApp()
const api = app.globalData.api

Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    floor:'',
    building:'',
    time_popup_show:false,
    type_popup_show:false,
    typeOption:[],
    nowType:'',
  },
  /**
   * 选择餐别
   */
  choose(e){
    let type = e.currentTarget.dataset.type;
    let that = this;
    api.curlPost('?cla=dormitoryApp&fun=search',{type:type,building:this.data.building}).then((res)=>{
        if(type == 'building'){
          that.setData({
            nowType:type,
            type_popup_show:true,
            typeOption:res.data.building
          })
        }else if(type =='floor'){
          that.setData({
            nowType:type,
            type_popup_show:true,
            typeOption:res.data.floor
          })
        }
      })
  },

  /**餐别确认 */
  onTypeConfirm(event){
    const { picker, value, index } = event.detail;
    if(this.data.nowType =='building'){
      
      this.setData({
        building:value,
        type_popup_show:false
      })
    
    }else if(this.data.nowType == 'floor'){
      this.setData({
        floor:value,
        type_popup_show:false
      })
    }

    this.getMenu();
  },
  onTypeCancel(e){
    this.setData({
      type_popup_show:false
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // let id = options.id;
    
  },

  //获取菜单
  getMenu(){
    let that = this;
    let para = {
      building:this.data.building,
      floor:this.data.floor,
    }
    if(api.isBlank(para.building) || api.isBlank(para.floor)){
      return false;
    }
    api.curlPost('?cla=dormitoryApp&fun=list',para).then((res)=>{
      that.setData({
        list:res.data.list
      })
    })

  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
   
  },
  
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})